/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package models;

/**
 * Includes all the loss equations given as the ratio Pt/Pr (power of transmision/reception)
 * @author Arvanitis Ioannis
 */
public final class Losses {

    private static double PI = Math.PI; //π
    private static int C = 299792458; //light speed (m/s)
    private static int MHz = 1000000; //MHz
    
    /**
     * Gets the Free Space Path Loss
     * @param distance Distance between transmitter and receiver
     * @param frequency Frequency used (in MHz)
     * @return the Free Space Path Loss
     */
    public static double getFreeSpacePathLoss(double distance, int frequency) {
        return Math.pow(4*PI*distance*frequency*MHz/C,2);
    }

    /**
     * Gets the Loss according to Basic Friis Transmission Equation
     * @param gainOfTransmitter Gain of the transmitting antenna
     * @param gainOfReceiver Gain of the receiving antenna
     * @param distance Distance between transmitter and receiver
     * @param frequency Frequency used (in MHz)
     * @return the Loss according to Friis Transmission Equation
     */
    public static double getBasicFriisTransmissionLoss(double gainOfTransmitter, double gainOfReceiver, double distance, int frequency) {
        return Math.pow(4*PI*distance*frequency*MHz/C,2)/(gainOfTransmitter*gainOfReceiver);
    }

    /**
     * Gets the Loss according to Empirical Friis Transmission Equation
     * @param gainOfTransmitter Mean effective gain of the transmitting antenna
     * @param gainOfReceiver Mean effective gain of the receiving antenna
     * @param distance Distance between transmitter and receiver
     * @param frequency Frequency used (in MHz)
     * @param n Experimentally determined parameter, typically in the range of 3 to 5
     * @return the Loss according to Empirical Friis Transmission Equation
     */
    public static double getEmpiricalFriisTransmissionLoss(double gainOfTransmitter, double gainOfReceiver, double distance, int frequency, double n) {
        return Math.pow(4*PI*frequency*MHz/C,2)/(gainOfTransmitter*gainOfReceiver)*Math.pow(distance, n);
    }

    /**
     * Returns a result in appropriate format
     * @param res Result in some format
     * @param dB Whether the result has to be transformed in dB or the opposite
     * @return a result in appropriate format
     */
    public static double getResultInDecibels(double res, boolean dB) {
        if (dB) {
//            System.out.println(res);
//            System.out.println(10*Math.log10(res));
            return 10*Math.log10(res);
        }
        else {
            return Math.pow(10, res/10);
        }
    }
}
